import { Component, ViewChild } from '@angular/core';
import { NavParams, Events, AlertController, App, ModalController, NavController, Content, ActionSheetController, LoadingController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { Config } from '../../../../../providers/config';
import { DomSanitizer } from '@angular/platform-browser';
import _ from 'lodash';
import * as moment from "moment";
import {IrpInternalReportDetailService} from "../detail/detail.service";
import { Common } from "../../../../../providers/common";

@Component({
  selector: 'page-irp-report-inside-detail',
  templateUrl: './detail.html',
  providers:[IrpInternalReportDetailService]
})
export class IrpInternalReportDetailPage {
	moa_page_name: any = "page-irp-report-inside-detail";
  moa_page_explain: any = "内部研报详情";
  
    public logonname:any;
    // 用户orgid
    public orgid:any= [];
    // 报告信息
    public info:any ;
    // 报告ID
    public reportid: any;
    // 评论框状态
    public isCommentStatus= false;
    // 评论内容
    public commentContent:any;
    // 评论列表
    public CommentList:any = [];
    
   

  constructor(
    public alertCtrl: AlertController,
    public app: App,
    public modalCtrl: ModalController,
    public navCtrl: NavController,
    public config: Config,
    private sanitizer: DomSanitizer,
    public events: Events,
    public storage: Storage,
    private common: Common,
    private actionSheetCtrl: ActionSheetController,
    private navParams: NavParams,
    public loadingCtrl: LoadingController,
    public IrpInternalReportDetail:IrpInternalReportDetailService 
  ) {
    // 清空上次数据
    //this.info = null;
    //this.CommentList = [];
    // 获取传入报告信息
    this.info = this.navParams.data;
    // 获取报告id
    this.reportid = this.info.objid;
    // 获取用户登录名
    this.logonname = sessionStorage.getItem('logonname');
    // 获取用户orgid
    this.getOrgid(this.logonname);
    // 获取评论列表
    this.getCommentList(this.reportid);
    console.log("用户登录名 = "+this.logonname);
    console.log("报告信息 = "+JSON.stringify(this.info));
    
    }
      
  
  getCommentList(reportid){
    let that = this;
    this.IrpInternalReportDetail.getIrmReportComment(reportid).subscribe(data=> {
    if (data) {
    that.CommentList = _.pull(data,null);
    }
    })
    }
    // 评论弹出
    toggleComment(status){
    if(status=='start'){
    this.isCommentStatus = true;
    }
    if(status=='end'){
    this.isCommentStatus = false;
    }
    }
    

    // 获取登录人orgid
getOrgid(logonname){
  let that = this;
  this.IrpInternalReportDetail.getOrgid(logonname).subscribe(data=> {
  if (data) {
  that.orgid = data[0].orgid;
  }
  })
  }
  // 发送评论
  sendComment(){
  let that = this;
  this.commentContent = document.getElementById("areatext-content").innerHTML + "";
  this.IrpInternalReportDetail.sendIrmReportComment(that.orgid,that.reportid,this.commentContent).subscribe(data=>{
    if(data){

    }

  });
  that.getCommentList(that.reportid);
  }

  shareModel(){
    let actionSheet = this.actionSheetCtrl.create({
      buttons: [
        {
          text: '微信分享',
          handler: () => {
          }
        },
        {
          text: '微信分享朋友圈',
          handler: () => {
          }
        },
        {
          text: '取消分享',
          role: 'cancel',
          handler: () => {
          }
        }
      ]
    });
 
    actionSheet.present();
  }
  }
